<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller {

    function __construct() {
        //继承父类
        parent::__construct();
    }

    //空方法，防止报错
    public function _empty() {
        $this->index();
    }

    //提交评测基础数据
    public function index(){
    	if(IS_POST){
			$info=I("info");
			$info['item_addtime']=SYS_TIME;
			$item_id=M("Iteminfo")->add($info);
			if($item_id){
				redirect(U('index/rating',array("item_id"=>$item_id)),0, '页面跳转中...');
			}else{
				$this->error('参数错误，请重新来过！',U('index/index'),3);
			}
		}else{
			//行业分类信息
			$indusinfo=M("Industry")->where("indus_pid=0")->select();
			foreach($indusinfo as $k=>$v){
				$child=M("Industry")->where("indus_pid=".$v['indus_id'])->select();
				$indusinfo[$k]['child']=$child;
				$indusinfo[$k]['childnum']=sizeof($child);
			}
			$this->assign('indusinfo',$indusinfo);
			//省信息
			$provinces=M("Provinces")->where("1")->select();
			$this->assign('provinces',$provinces);
			$this->display();
		}

    }


    //评级报表
	public function rating(){
		$item_id=I("get.item_id")?I("get.item_id"):4;
		if(IS_POST){
			$rating=I("info");
			$flag=D('Rating')->arrange($item_id,$rating);
			//查看项目行业是否启用
			$iteminfo=M("Iteminfo")->join("left join ec_industry on ec_iteminfo.indus_id=ec_industry.indus_id")->where("item_id=".$item_id)->field("ec_iteminfo.*,ec_industry.indus_isopen,ec_industry.indus_score,ec_industry.indus_weight")->find();
			if($iteminfo['indus_isopen']==1){//1为启用，2为测试
				redirect(U('index/index',array("item_id"=>$item_id)),0, '页面跳转中...');
			}elseif($iteminfo['indus_isopen']==2){
				$this->success('请耐心等待专家测评！',U('index/indexinfo',array("item_id"=>$item_id)),3);
			}
		}else{
			//项目基本信息
			$iteminfo=M("Iteminfo")->where("item_id=".$item_id)->find();
			$this->assign('iteminfo',$iteminfo);
			//评测项信息
			$rateinfo=D('Rating')->rateinfo($item_id);
			$this->assign('rateinfo',$rateinfo);

			$this->display();
		}
	}
    

	//后台手动设置分值-并计算总分计入项目信息中
    public function indexinfo() {
		$item_id=I("get.item_id")?I("get.item_id"):4;
		//基本信息预览展示
            $iteminfo = M("iteminfo")->where("item_id=" . $item_id)->find();
            $this->assign('iteminfo', $iteminfo); 

		 //行业分类信息
            $indusinfo = M("Industry")->where("indus_pid=0")->select();
            foreach ($indusinfo as $k => $v) {
                $child = M("Industry")->where("indus_pid=" . $v['indus_id'])->select();
                $indusinfo[$k]['child'] = $child;
                $indusinfo[$k]['childnum'] = sizeof($child);
            }
            $this->assign('indusinfo', $indusinfo);
		 	//省信息
            $provinces = M("Provinces")->where("1")->select();
            $this->assign('provinces', $provinces);
            //市信息
            $cities = M("Cities")->where("1")->select();
            $this->assign('cities', $cities);

		$this->display();
    }


    //根据省名称获取市信息
	public function getcity(){
		$province=I("get.province");
		$citys=M("Cities")->where("ec_provinces.province='".trim($province)."'")->join("left join ec_provinces on ec_provinces.id=ec_cities.provinceid")->field("ec_cities.*")->select();
		$this->ajaxReturn(array("data"=>$citys));
	}


	


	
}
